libxenlight: tests a lots more of xl return value inside the library
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:02:29 +0000 (07:02 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:02:29 +0000 (07:02 +0000)
and in xl.

introducing a domain where the xenguest build function has fail, lead
to having xenstored receiving SIGBUS, since it's trying to access some
of the domain's memory, which haven't been properly allocated. (it
doesn't seems to be a way to make xenstored more robust to this though
since xc_map_foreign_range just succeed).

make xl a lot more robust regarding all those random errors possible.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/xl.c

index c2dcbcc52d484cff3113ca331494450567ec781b..15299ea346284d5f449d9ea655293ffefb8dba86 100644 (file)
@@ -176,18 +176,24 @@ retry_transaction:
 int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, libxl_domain_build_state *state)
 {
     char **vments = NULL, **localents = NULL;
-    int i;
+    int i, ret;
+
+    ret = build_pre(ctx, domid, info, state);
+    if (ret) goto out;
 
-    build_pre(ctx, domid, info, state);
     if (info->hvm) {
-        build_hvm(ctx, domid, info, state);
+        ret = build_hvm(ctx, domid, info, state);
+        if (ret) goto out;
+
         vments = libxl_calloc(ctx, 5, sizeof(char *));
         vments[0] = "rtc/timeoffset";
         vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
         vments[2] = "image/ostype";
         vments[3] = "hvm";
     } else {
-        build_pv(ctx, domid, info, state);
+        ret = build_pv(ctx, domid, info, state);
+        if (ret) goto out;
+
         vments = libxl_calloc(ctx, 9, sizeof(char *));
         i = 0;
         vments[i++] = "image/ostype";
@@ -203,8 +209,9 @@ int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uin
             vments[i++] = (char*) info->u.pv.cmdline;
         }
     }
-    build_post(ctx, domid, info, state, vments, localents);
-    return 0;
+    ret = build_post(ctx, domid, info, state, vments, localents);
+out:
+    return ret;
 }
 
 int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
@@ -212,10 +219,14 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
                          libxl_device_model_info *dm_info)
 {
     char **vments = NULL, **localents = NULL;
-    int i;
+    int i, ret;
+
+    ret = build_pre(ctx, domid, info, state);
+    if (ret) goto out;
+
+    ret = restore_common(ctx, domid, info, state, fd);
+    if (ret) goto out;
 
-    build_pre(ctx, domid, info, state);
-    restore_common(ctx, domid, info, state, fd);
     if (info->hvm) {
         vments = libxl_calloc(ctx, 5, sizeof(char *));
         vments[0] = "rtc/timeoffset";
@@ -238,13 +249,15 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
             vments[i++] = (char*) info->u.pv.cmdline;
         }
     }
-    build_post(ctx, domid, info, state, vments, localents);
+    ret = build_post(ctx, domid, info, state, vments, localents);
+    if (ret) goto out;
+
     if (info->hvm)
         asprintf(&(dm_info->saved_state), "/var/lib/xen/qemu-save.%d", domid);
     else
         dm_info->saved_state = NULL;
-
-    return 0;
+out:
+    return ret;
 }
 
 int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid)
index 3be7acf0a492f1b1a6e3ecdee03ab983df6794c1..2322ce4a67e3ff909cf0738b1031f54c36f8ad9c 100644 (file)
@@ -750,6 +750,7 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
     int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
     int i, fd;
     int need_daemon = 1;
+    int ret;
     libxl_device_model_starting *dm_starting = 0;
     libxl_waiter *w1 = NULL, *w2 = NULL;
     memset(&dm_info, 0x00, sizeof(dm_info));
@@ -768,29 +769,47 @@ start:
     }
 
     libxl_ctx_set_log(&ctx, log_callback, NULL);
-    libxl_domain_make(&ctx, &info1, &domid);
+
+    ret = libxl_domain_make(&ctx, &info1, &domid);
+    if (ret) {
+        fprintf(stderr, "cannot make domain: %d\n", ret);
+        return;
+    }
 
     if (!restore_file || !need_daemon) {
         if (dm_info.saved_state) {
             free(dm_info.saved_state);
             dm_info.saved_state = NULL;
         }
-        libxl_domain_build(&ctx, &info2, domid, &state);
+        ret = libxl_domain_build(&ctx, &info2, domid, &state);
     } else {
         int restore_fd;
 
         restore_fd = open(restore_file, O_RDONLY);
-        libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
+        ret = libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
         close(restore_fd);
     }
 
+    if (ret) {
+        fprintf(stderr, "cannot (re-)build domain: %d\n", ret);
+        return;
+    }
+
     for (i = 0; i < num_disks; i++) {
         disks[i].domid = domid;
-        libxl_device_disk_add(&ctx, domid, &disks[i]);
+        ret = libxl_device_disk_add(&ctx, domid, &disks[i]);
+        if (ret) {
+            fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret);
+            return;
+        }
     }
     for (i = 0; i < num_vifs; i++) {
         vifs[i].domid = domid;
-        libxl_device_nic_add(&ctx, domid, &vifs[i]);
+        ret = libxl_device_nic_add(&ctx, domid, &vifs[i]);
+        if (ret) {
+            fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret);
+            return;
+        }
     }
     if (info1.hvm) {
         dm_info.domid = domid;